

using System;
using System.Globalization;
using System.Text.RegularExpressions;

namespace JTC.MiniCommerce.Store {
  public class StoreUtility {
  
    #region Methods
    
    #region Public

    /// <summary>
    /// Gets the formatted amount.
    /// </summary>
    /// <param name="amount">The amount.</param>
    /// <param name="formatWithCurrencySymbol">if set to <c>true</c> [format with currency symbol].</param>
    /// <returns></returns>
    public static string GetFormattedAmount(decimal amount, bool formatWithCurrencySymbol) {
      SiteSettings siteSettings = SiteSettings.Load();
      CultureInfo cultureInfo = new CultureInfo(siteSettings.Language);
      if(formatWithCurrencySymbol) {
        return string.Format("{0} {1}", siteSettings.CurrencySymbol, decimal.Round(amount, cultureInfo.NumberFormat.CurrencyDecimalDigits).ToString(cultureInfo));
      }
      else {
        return decimal.Round(amount, cultureInfo.NumberFormat.CurrencyDecimalDigits).ToString(cultureInfo);
      }
    }

    /// <summary>
    /// Gets the formatted amount.
    /// </summary>
    /// <param name="amount">The amount.</param>
    /// <param name="formatWithCurrencySymbol">if set to <c>true</c> [format with currency symbol].</param>
    /// <returns></returns>
    public static string GetFormattedAmount(string amount, bool formatWithCurrencySymbol) {
      decimal parsedAmount = 0;
      parsedAmount = decimal.Parse(amount);
      return GetFormattedAmount(parsedAmount, formatWithCurrencySymbol);
    }

    /// <summary>
    /// Gets the formatted date.
    /// </summary>
    /// <param name="date">The date.</param>
    /// <returns></returns>
    public static string GetFormattedDate(DateTime date) {
      SiteSettings siteSettings = SiteSettings.Load();
      CultureInfo cultureInfo = new CultureInfo(siteSettings.Language);
      return date.ToString("D", cultureInfo);
    }

    #endregion
    
    #endregion

  }
}
